package kr.co.boogui.dao;

import java.util.List;

import kr.co.boogui.model.CinemaVO;
import kr.co.boogui.model.MovieVO;
import kr.co.boogui.model.ShowingParamVO;
import kr.co.boogui.model.ShowingVO;
import mybatis3.helper.MVCSqlSessionFactory;

import org.apache.ibatis.session.SqlSession;

public class ShowingDAO {

	public static boolean insertShowing(ShowingVO s) {
		boolean result = false;
		String shno = "";
		SqlSession sess = null;
		ShowingParamVO sp = new ShowingParamVO();
		try {
			sess = MVCSqlSessionFactory.openSession();
			int i = sess.insert("ShowingMapper.insertShowingSQL", s);
			sess.commit();
			shno = sess.selectOne("ShowingMapper.readShnoSQL");
			sp.setShno(shno);			
			int r = sess.insert("ShowingMapper.insertSeatinfoSQL", sp);			 
			sess.update("ShowingMapper.updateIsplaySQL", s.getMovno());
			sess.commit();
			if(i>0 && r>0)result = true;
		} finally {
			sess.close();
		}		
		return result;
	}
	
	public static List<MovieVO> readMovieTitle() {
		List<MovieVO> result = null;
		SqlSession sess = null;
		try {
			sess = MVCSqlSessionFactory.openSession();
			result = sess.selectList("ShowingMapper.readMovieTitSQL");			
		} finally {
			sess.close();
		}
		return result;
	}
	
	public static List<ShowingParamVO> readCineLocation() {
		List<ShowingParamVO> result = null;
		SqlSession sess = null;
		try {
			sess = MVCSqlSessionFactory.openSession();
			result = sess.selectList("ShowingMapper.readCineLocSQL");
		} finally {
			sess.close();
		}
		return result;
	}	
	
	public static List<CinemaVO> readCineName(String addrkey) {
		List<CinemaVO> result = null;
		SqlSession sess = null;
		try {
			sess = MVCSqlSessionFactory.openSession();
			result = sess.selectList("ShowingMapper.readCineNameSQL", addrkey);			
		} finally {
			sess.close();
		}
		return result;
	}
	
}
